package com.cf.studiomanage.mapper;

import com.cf.studiomanage.entity.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("INSERT INTO message(user_id, type, content, is_read) VALUES(#{userId}, #{type}, #{content}, FALSE)")
    int send(Message message);

    @Select("SELECT * FROM message WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<Message> getByUser(Long userId);

    @Update("UPDATE message SET is_read = TRUE WHERE id = #{id}")
    int markAsRead(Long id);
}
